//
//  FProgressBar.m
//  go2
//
//  Created by 袁飞 on 12-7-21.
//
//

#import "FProgressBar.h"

@implementation FProgressBar
-(id)initWithBK:(NSString*)bkname Bar:(NSString*)barname Total:(int)total{
  [super init];
  bk_ = [CCSprite spriteWithSpriteFrameName:bkname];
  bar_ = [CCSprite spriteWithSpriteFrameName:barname];
  
  //[bk setAnchorPoint:ccp(0, 0)];
  //[bar setAnchorPoint:ccp(0, 0)];
  
  [self addChild:bk_];
  [self addChild:bar_];
  return self;
}

-(void)onTouchDown:(CGPoint)point{
  CGSize s = [bar_ textureRect].size;
  int x = point.x + s.width/2;
  float rt = x/s.width;
  
  x = s.width/2 - rt*s.width/2;
  
  [bar_ setScaleX:rt];
  [bar_ setPosition:ccp(-x, 0)];
}

-(CGRect)getControlRect{
  CGRect rect = [bar_ textureRect];
  CGPoint ap = [bar_ anchorPoint];
  float x = -rect.size.width*ap.x;
  float y = -rect.size.height*ap.y;
  //NSLog(@"size %f, %f %f, %f",x, y, rect.size.width, rect.size.height);
  return CGRectMake(x, y, rect.size.width, rect.size.height);
}

@end
